package cn.stronglink.asset.module.assetmanage.cabinet.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.AssetModel;
import cn.stronglink.asset.model.AssetType;
import cn.stronglink.asset.model.CabinetExt;
import cn.stronglink.asset.module.assetmanage.cabinet.service.CabinetExtService;
import cn.stronglink.asset.module.assetmanage.cabinet.vo.CabinetExtVo;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value = "cabinet")
public class CabinetExtController extends AbstractController {

	@Autowired
	private CabinetExtService cabinetExtService;

	/**
	 * 查询机柜列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "list")
	public ResponseEntity<ModelMap> qryCabinetList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		List<CabinetExtVo> data = cabinetExtService.qryCabinetList(params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查询机柜得温湿度
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "searchTemperature")
	public ResponseEntity<ModelMap> searchTemperature(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<HashMap<String,Object>> page = (Page<HashMap<String,Object>>) super.getPage(params);
		Page<HashMap<String,Object>> data = cabinetExtService.searchTemperature(page,params);
		return setSuccessModelMap(modelMap, data);
	} 
	/**
	 * 查询机柜列表 带分页
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "qryList")
	public ResponseEntity<ModelMap> qryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		@SuppressWarnings("unchecked")
		Page<CabinetExtVo> page  = (Page<CabinetExtVo>) super.getPage(params);
		Page<CabinetExtVo> data = cabinetExtService.qryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 编辑机柜信息
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param cabinetExt
	 * @return
	 */
	@OperateLog(module = "机柜管理",desc="添加机柜", type = OpType.ADD)
	@RequestMapping(value = "create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody CabinetExtVo cabinetExt) {	
		cabinetExtService.create(cabinetExt);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 编辑机柜信息
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param cabinetExt
	 * @return
	 */
	@OperateLog(module = "机柜管理",desc="修改机柜信息", type = OpType.UPDATE)
	@RequestMapping(value = "edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody CabinetExtVo cabinetExt) {	
		cabinetExtService.edit(cabinetExt);
		return setSuccessModelMap(modelMap, null);
	}
	/**
	 * 根据id查询
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String, Object> params) {	
		List<CabinetExtVo> data = cabinetExtService.qryById(params);
		return setSuccessModelMap(modelMap, data);
	}
	/**
	 * 移除
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@OperateLog(module = "机柜管理",desc="删除机柜", type = OpType.DEL)
	@RequestMapping(value = "remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		cabinetExtService.remove(id);
		return setSuccessModelMap(modelMap, null);
	}
	
	/**
	 * 查询机柜类型列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryRackTypeList")
	public ResponseEntity<ModelMap> qryRackTypeList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response) {	
		List<AssetType> data = cabinetExtService.qryRackTypeList();
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查询机柜品牌列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryRackModelList")
	public ResponseEntity<ModelMap> qryRackModelList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {	
		List<AssetModel> data = cabinetExtService.qryRackModelList(params);
		return setSuccessModelMap(modelMap, data);
	}
	
	/**
	 * 查询机柜所在行列表
	 * @param modelMap
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "qryCabinetExtList")
	public ResponseEntity<ModelMap> qryCabinetExtList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Map<String, Object> params) {	
		List<CabinetExt> data = cabinetExtService.qryCabinetExtList(params);
		return setSuccessModelMap(modelMap, data);
	}
	
	
	
}
